<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>教室信息管理</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/font.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <script type="text/javascript" src="https://cdn.bootcdn.net/ajax/libs/Swiper/3.4.2/js/swiper.jquery.min.js"></script>
    <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/Swiper/3.4.2/css/swiper.min.css">
    <script src="${pageContext.request.contextPath}/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/xadmin.js"></script>
</head>
<body>
<!-- 顶部开始 -->
<div class="container">
    <div class="logo"><a href="./index.html">健身房管理系统 V1.1</a></div>
    <div class="open-nav"><i class="iconfont">&#xe699;</i></div>
    <ul class="layui-nav right" lay-filter="">
        <li class="layui-nav-item">
            <a href="javascript:;">管理员</a>
            <dl class="layui-nav-child">
                <dd><a href="${pageContext.request.contextPath}/member/outlogin.action">退出</a></dd>
            </dl>
        </li>
        <li class="layui-nav-item"><a href="${pageContext.request.contextPath}/index.jsp">前台首页</a></li>
    </ul>
</div>
<!-- 顶部结束 -->
<!-- 中部开始 -->
<div class="wrapper">
    <!-- 左侧菜单开始 -->
    <div class="left-nav">
        <div id="side-nav">
            <jsp:include page="left.jsp"/>
        </div>
    </div>
    <!-- 左侧菜单结束 -->
    <!-- 右侧主体开始 -->
    <div class="page-content">
        <div class="content" >
            <!-- 右侧内容框架，更改从这里开始 -->
            <form class="layui-form xbs" action="" >
                <div class="layui-form-pane" style="text-align: center;">
                    <div class="layui-form-item" style="display: inline-block;">
                        <div class="layui-input-inline">
                            <input type="text" id="classroomname"  placeholder="请输入教室类型" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-input-inline" style="width:80px">
                            <button type="button" class="layui-btn"  lay-submit="" lay-filter="" onclick="findMem()"><i class="layui-icon">&#xe615;</i></button>
                        </div>
                    </div>
                </div>
            </form>
            <div id="table">
                <xblock>
                    <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon">&#xe640;</i>批量删除</button>
                    <button class="layui-btn" onclick="member_add('添加教室','${pageContext.request.contextPath}/adminClassroom_add.jsp','','400')"><i class="layui-icon">&#xe608;</i>添加</button>
                    <span class="x-right" style="line-height:40px">共有数据:${classroomInfo.list.size()}条</span>
                </xblock>
                <table class="layui-table">
                    <thead>
                    <tr>
                        <th>
                            <input type="checkbox" name="" value="">
                        </th>
                        <th>ID</th>
                        <th>教室名</th>
                        <th>最大容量</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <c:forEach items="${classroomInfo.list}" var="classroom">
                        <tr>
                            <td>
                                <input type="checkbox" value="1" name="">
                            </td>
                            <td>${classroom.classroomid}</td>
                            <td>${classroom.classroomname}</td>
                            <td>${classroom.maxmem}</td>
                            <td class="td-manage">
                                <a title="编辑" href="javascript:;" onclick="editMem(${classroom.classroomid})" class="ml-5" style="text-decoration:none">
                                    <i class="layui-icon">&#xe642;</i>
                                </a>
                                &nbsp;&nbsp;
                                <a title="删除" href="javascript:;" onclick="member_del(${classroom.classroomid})"
                                   style="text-decoration:none">
                                    <i class="layui-icon">&#xe640;</i>
                                </a>
                            </td>
                        </tr>
                    </c:forEach>

                    </tbody>
                </table>
            </div>
<%--            分页--%>
            <div id="bottom">
                <div>
                    <nav aria-label="..." style="text-align:center;">
                        <ul class="pagination layui-laypage" style="white-space: nowrap">
<%--                            向前翻页--%>
                            <li style="display: inline-block"><a href="javascript:ajaxsplit(${classroomInfo.prePage})" aria-label="Previous">&laquo;</a></li>

                            <c:forEach begin="1" end="${classroomInfo.pages}" var="i">
                                <c:if test="${classroomInfo.pageNum==i}">
                                    <li style="display: inline-block">
                                        <a href="javascript:ajaxsplit(${i})"
                                           style="background-color: #DFDFDF">${i}</a>
                                    </li>
                                </c:if>
                                <c:if test="${classroomInfo.pageNum!=i}">
                                    <li style="display: inline-block">
                                        <a href="javascript:ajaxsplit(${i})">${i}</a>
                                    </li>
                                </c:if>
                            </c:forEach>
<%--                            向后翻页--%>
                            <li style="display: inline-block"><a href="javascript:ajaxsplit(${classroomInfo.nextPage})" aria-label="Previous">&raquo;</a></li>
                        </ul>
                    </nav>
                </div>
            </div>
            <!-- 右侧内容框架，更改从这里结束 -->
        </div>
    </div>
    <!-- 右侧主体结束 -->
</div>
<!-- 中部结束 -->
<!-- 页面动态效果 -->
<script>
    //分页
    function ajaxsplit(page) {
        //异步ajax分页请求
        var a = $("#classroomname").val();
        if (a.length==0){
            $.ajax({
                url:"${pageContext.request.contextPath}/admin/ajaxClassroom.action",
                data:{"page":page},
                type:"post",
                success:function () {
                    //更新id=table部分内容
                    $("#table").load("http://localhost:8080/GamnasiumSystem/adminClassroom_list.jsp #table");
                }
            });
        }else {
            $.ajax({
                url:"${pageContext.request.contextPath}/admin/findClassroomSplit.action",
                data:{
                    page:page,
                    classroomname:$("#classroomname").val()
                },
                type:"post",
                success:function () {
                    //更新id=table部分内容
                    $("#table").load("http://localhost:8080/GamnasiumSystem/adminClassroom_list.jsp #table");
                }
            });
        }


    }
    //多条件搜索，用Ajax发送请求,然后更新session=memInfo内容
    function findMem(){
        $.ajax({
            url: "${pageContext.request.contextPath}/admin/findClassroom.action",
            type: "post",
            data: {classroomname:$("#classroomname").val()},
            success:function (){
                //更新id=table部分内容
                $("#table").load("http://localhost:8080/GamnasiumSystem/adminClassroom_list.jsp #table");
            },
            error:function (){
                console.log("error");
            }
        });
    }
    //编辑用户信息
    function editMem(index){
        console.log(index);
        $.ajax({
            url: "${pageContext.request.contextPath}/admin/editClassroomShow.action",
            type: "post",
            data: {
                classroomid:index
            },
            success:function (){
                console.log("result");
                //查到要修改的人就弹出
                x_admin_show('编辑','${pageContext.request.contextPath}/adminClassroom_edit.jsp','','400');
            },
            error:function (){
                console.log("error");
            }
        });
    }
    /*用户-删除*/
    function member_del(obj){
        console.log(obj);
        layer.confirm('确认要删除吗？',function(){
            //发异步删除数据
            $.ajax({
                url: "${pageContext.request.contextPath}/admin/delClassroom.action",
                type: "post",
                data: {
                classroomid:obj
                },
                success:function (result){
                    console.log(result);
                    if (result=="ok"){
                        window.top.location.href="http://localhost:8080/GamnasiumSystem/admin/toClassroomPage.action";
                    }else {
                        layer.msg('删除失败，请重试！',{icon:1});
                    }
                },
                error:function (){
                    console.log("error");
                }
            });
        });
    }
</script>
<script>

    //日期范围
    layui.use(['laydate'], function(){
        laydate = layui.laydate;//日期插件
        //以上模块根据需要引入
        //
        var start = {
            min: laydate.now()
            ,max: '2099-06-16 23:59:59'
            ,istoday: false
            ,choose: function(datas){
                end.min = datas; //开始日选好后，重置结束日的最小日期
                end.start = datas //将结束日的初始值设定为开始日
            }
        };
        var end = {
            min: laydate.now()
            ,max: '2099-06-16 23:59:59'
            ,istoday: false
            ,choose: function(datas){
                start.max = datas; //结束日选好后，重置开始日的最大日期
            }
        };

        document.getElementById('LAY_demorange_s').onclick = function(){
            start.elem = this;
            laydate(start);
        }
        document.getElementById('LAY_demorange_e').onclick = function(){
            end.elem = this
            laydate(end);
        }

    });

    //批量删除提交
    function delAll () {
        layer.confirm('确认要删除吗？',function(index){
            console.log(index);
            //捉到所有被选中的，发异步进行删除
            layer.msg('删除成功', {icon: 1});
        });
    }
    /*用户-添加*/
    function member_add(title,url,w,h){
        x_admin_show(title,url,w,h);
    }
    /*用户-查看*/
    function member_show(title,url,id,w,h){
        x_admin_show(title,url,w,h);
    }

    /*用户-停用*/
    function member_stop(obj,id){
        layer.confirm('确认要停用吗？',function(index){
            //发异步把用户状态进行更改
            $(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="member_start(this,id)" href="javascript:;" title="启用"><i class="layui-icon">&#xe62f;</i></a>');
            $(obj).parents("tr").find(".td-status").html('<span class="layui-btn layui-btn-disabled layui-btn-mini">已停用</span>');
            $(obj).remove();
            layer.msg('已停用!',{icon: 5,time:1000});
        });
    }

    /*用户-启用*/
    function member_start(obj,id){
        layer.confirm('确认要启用吗？',function(index){
            //发异步把用户状态进行更改
            $(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="member_stop(this,id)" href="javascript:;" title="停用"><i class="layui-icon">&#xe601;</i></a>');
            $(obj).parents("tr").find(".td-status").html('<span class="layui-btn layui-btn-normal layui-btn-mini">已启用</span>');
            $(obj).remove();
            layer.msg('已启用!',{icon: 6,time:1000});
        });
    }
    // 用户-编辑
    function member_edit (title,url,id,w,h) {
        x_admin_show(title,url,w,h);
    }
    /*密码-修改*/
    function member_password(title,url,id,w,h){
        x_admin_show(title,url,w,h);
    }
    /*用户-删除*/
    // function member_del(obj,id){
    //     layer.confirm('确认要删除吗？',function(index){
    //         //发异步删除数据
    //         $(obj).parents("tr").remove();
    //         layer.msg('已删除!',{icon:1,time:1000});
    //     });
    // }
</script>
</body>
</html>
